/*
 * Course:    CS 590 Web Services
 * Semseter:  Spring 2009
 * Professor: Sedlemeyer
 * Project:   CHEAT (Code Help Educational Assignment Tool)
 * Due Date:  May 1, 2009
 * Team:      Sarcasm
 *            (Baker, Jason; Mitchell, Robin; Shie, Keith)
 */

package cheat.entities;

import cheat.entities.keys.AssignmentKeywordPK;
import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.IdClass;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.Table;

/**
 * Holds the keyword metadata associated with the assignment.
 *
 * <p>There are three kinds of keywords:<ul>
 * <li>Topics</li>
 * <li>Prerequisites</li>
 * <li>Other</li>
 * </ul></p>
 *
 * @author Keith Shie
 */
@Entity
@Table(name = "asgn_content")
@IdClass(AssignmentKeywordPK.class)
@NamedQueries({@NamedQuery(name = "AssignmentKeyword.findAll",
                    query = "SELECT a FROM AssignmentKeyword a"),
        @NamedQuery(name = "AssignmentKeyword.findByUuid",
                    query ="SELECT a FROM AssignmentKeyword a WHERE a.uuid = :uuid"),
        @NamedQuery(name = "AssignmentKeyword.findByKeywordCode",
                    query = "SELECT a FROM AssignmentKeyword a WHERE a.keywordCode = :keywordCode"),
        @NamedQuery(name = "AssignmentKeyword.findByValue",
                    query = "SELECT a FROM AssignmentKeyword a WHERE a.contentValue = :contentValue")})
public class AssignmentKeyword implements Serializable {
  private static final long serialVersionUID = 1L;
  @Id
  @Basic(optional = false)
  @Column(name = "uuid", nullable = false)
  private int uuid;
  @Id
  @Basic(optional = false)
  @Column(name = "asgncntcd", nullable = false, length = 8)
  private String keywordCode;
  @Id
  @Basic(optional = false)
  @Column(name = "value", nullable = false, length = 30)
  private String contentValue;
  @JoinColumn(name = "asgncntcd", referencedColumnName = "asgncntcd", nullable = false, insertable = false, updatable =
          false)
  @ManyToOne(optional = false)
  private AssignmentKeywordType keywordType;
  @JoinColumns({@JoinColumn(name = "uuid", referencedColumnName = "uuid", nullable = false, insertable = false, updatable =
          false)})
  @ManyToOne(optional = false)
  private AssignmentProperty assignmentProperty;

  public AssignmentKeyword() {
  }

  public AssignmentKeyword(int uuid, String keywordCode, String value) {
    this.uuid = uuid;
    this.keywordCode = keywordCode;
    this.contentValue = value;
  }

  public AssignmentKeywordType getKeywordType() {
    return keywordType;
  }

  public void setKeywordType(AssignmentKeywordType keywordType) {
    this.keywordType = keywordType;
  }

  public AssignmentProperty getAssignmentProperty() {
    return assignmentProperty;
  }

  public void setAssignmentProperty(AssignmentProperty assignmentProperty) {
    this.assignmentProperty = assignmentProperty;
  }


  public String getKeywordCode() {
    return keywordCode;
  }


  public void setKeywordCode( String keywordCode ) {
    this.keywordCode = keywordCode;
  }


  public String getContentValue() {
    return contentValue;
  }


  public void setContentValue( String contentValue ) {
    this.contentValue = contentValue;
  }


  public int getUuid() {
    return uuid;
  }


  public void setUuid( int uuid ) {
    this.uuid = uuid;
  }

  @Override
  public int hashCode() {
    int hash = 0;
    hash += (int) uuid;
    hash += (keywordCode != null ? keywordCode.hashCode() : 0);
    hash += (contentValue != null ? contentValue.hashCode() : 0);
    return hash;
  }

  @Override
  public boolean equals(Object object) {
    // TODO: Warning - this method won't work in the case the id fields are not set
    if (!(object instanceof AssignmentKeyword)) {
      return false;
    }
    AssignmentKeyword other = (AssignmentKeyword) object;
    if (this.uuid != other.uuid) {
      return false;
    }
    if ((this.keywordCode == null && other.keywordCode != null) || (this.keywordCode != null && !this.keywordCode.equals(other.keywordCode))) {
      return false;
    }
    if ((this.contentValue == null && other.contentValue != null) || (this.contentValue != null && !this.contentValue.equals(other.contentValue))) {
      return false;
    }
    return true;
  }

  @Override
  public String toString() {
    return "cheat.entities.AssignmentKeyword[uuid=" + uuid + ", keywordCode=" + keywordCode + ", value=" + contentValue + "]";
  }

}
